//package com.smedi.ismedi.constructionproject.core.application.data;
//
//import com.smedi.ismedi.constructionproject.core.domain.repository.ProjectBasicRepository;
//import com.smedi.ismedi.constructionproject.core.port.adapter.persistence.model.ProjectBasicEntity;
//import com.smedi.ismedi.constructionproject.core.port.adapter.persistence.mybatis.mapper.ProjectBasicMapper;
//import com.smedi.ismedi.constructionproject.core.port.adapter.persistence.mybatis.mapper.RelationshipMapper;
//import com.smedi.ismedi.constructionproject.core.port.adapter.persistence.mybatis.mapper.TempMapper;
//import com.smedi.ismedi.database.starter.annotation.SkipSqlPermission;
//import com.smedi.ismedi.organization.api.dto.response.HrOrganizationResponse;
//import com.smedi.ismedi.organization.api.feign.RemoteHrOrganizationFeignApi;
//import com.smedi.ismedi.web.starter.util.DozerUtil;
//import lombok.NoArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.test.context.junit4.SpringRunner;
//
//import java.time.LocalDate;
//import java.time.LocalDateTime;
//import java.time.LocalTime;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.stream.Collectors;
//
//@SpringBootTest
//@RunWith(SpringRunner.class)
//@NoArgsConstructor
//@Slf4j
////@Transactional
////@Rollback
//// @Ignore
//public class ProjectAssignmentApplicationServiceImplTest {
//    @Autowired
//    TempMapper tempMapper;
//    @Autowired
//    RelationshipMapper relationshipMapper;
//    @Autowired
//    ProjectBasicMapper projectBasicMapper;
//    @Autowired
//    ProjectBasicRepository projectBasicRepository;
//    @Autowired
//    DozerUtil dozerUtil;
//    @Autowired
//    RemoteHrOrganizationFeignApi remoteHrOrganizationFeignApi;
//
//    @Test
//    @SkipSqlPermission
//    public void dataIn() {
//        List<Temp> temps = tempMapper.selectList(null);
//        List<ProjectBasicEntity> projectBasics = TempToProjectBasic(temps);
//        for (ProjectBasicEntity projectBasic : projectBasics) {
//            projectBasicMapper.insert(projectBasic);
//        }
//        int a = 1;
//    }
//
//    private List<ProjectBasicEntity> TempToProjectBasic(List<Temp> temps) {
//        //1.项目名称已经存在则不导入2.根据名称转换主体院Id
//        List<Relationship> relationships = relationshipMapper.selectList(null);
//        List<ProjectBasicEntity> projectBasicEntities = projectBasicMapper.selectList(null);
//        List<String> collect = projectBasicEntities.stream().map(ProjectBasicEntity::getProjectName).collect(Collectors.toList());
//        List<HrOrganizationResponse> data = remoteHrOrganizationFeignApi.getAllHrOrganizationList().getData();
//        List<ProjectBasicEntity> projectBasicEntities1 = new ArrayList<>();
//        for (Temp temp : temps) {
//            if (!collect.contains(temp.getProjectName())) {
//                ProjectBasicEntity convertor = dozerUtil.convertor(temp, ProjectBasicEntity.class);
//                convertor.setActualDurationBegin(StringTimeToLocalDateTime(temp.getContractDurationBegin1()));
//                convertor.setActualDurationEnd(StringTimeToLocalDateTime(temp.getContractDurationEnd2()));
//                convertor.setCreatedDate(StringTimeToLocalDateTimeTime(temp.getCreatedDate1()));
//                convertor.setLatestUpdatedDate(StringTimeToLocalDateTimeTime(temp.getLatestUpdatedDate1()));
//                Long hrOrganizationId = temp.getHrOrganizationId();
//                Relationship relationshipTemp = relationships.stream().filter(relationship -> relationship.getHrOrganizationId().equals(hrOrganizationId)).findFirst().orElse(null);
//                HrOrganizationResponse hrOrganizationResponse = data.stream().filter(x -> x.getFullName().equals(relationshipTemp.getHrOrganizationName())).findFirst().orElse(null);
//                if (null == hrOrganizationResponse || null == hrOrganizationResponse.getHrOrganizationId()) {
//                    log.error("hrOrganizationId：{}对应的imis组织不存在", hrOrganizationId);
//                } else {
//                    convertor.setHrOrganizationId(hrOrganizationResponse.getHrOrganizationId());
//                }
//                projectBasicEntities1.add(convertor);
//            } else {
//                log.info("{}:已经存在", temp.getProjectName());
//            }
//        }
//        return projectBasicEntities1;
//    }
//
//    private LocalDate StringTimeToLocalDateTime(String time) {
//        String var1 = StringUtils.split(time, " ")[0];
//        int year = Integer.parseInt(StringUtils.split(var1, "-")[0]);
//        int month = Integer.parseInt(StringUtils.split(var1, "-")[1]);
//        int day = Integer.parseInt(StringUtils.split(var1, "-")[2]);
//
//        return LocalDate.of(year, month, day);
//    }
//
//    private LocalDateTime StringTimeToLocalDateTimeTime(String time) {
//        String var1 = StringUtils.split(time, " ")[0];
//        int year = Integer.parseInt(StringUtils.split(var1, "-")[0]);
//        int month = Integer.parseInt(StringUtils.split(var1, "-")[1]);
//        int day = Integer.parseInt(StringUtils.split(var1, "-")[2]);
//        LocalDate localDate = LocalDate.of(year, month, day);
//
//        String var2 = StringUtils.split(time, " ")[1];
//        int hour = Integer.parseInt(StringUtils.split(var2, ":")[0]);
//        int minute = Integer.parseInt(StringUtils.split(var2, ":")[1]);
//        int second = Integer.parseInt(StringUtils.split(var2, ":")[2]);
//        LocalTime localTime = LocalTime.of(hour, minute, second);
//
//        return LocalDateTime.of(localDate, localTime);
//    }
//}